home *** CD-ROM | disk | FTP | other *** search
- /* 4567890123456789012345678901234567890123456789012345678901234567 */
- /*
- * File: AERequired.c
- * Author: Mark H. Linton
- * Creation Date: 2/4/95
- * Modification Date:
- * Description: A set of routines which may be used to handle
- * the processing of the four required AppleEvents.
- */
- #include <AppleEvents.h>
-
- #include "AERequired.h"
- #include "main.h"
-
- static Boolean GotAllParameters(AppleEvent *aMessage);
- static pascal OSErr HandleOAPP(AppleEvent *aMessage,
- AppleEvent *aReply, long aRefCon);
- static pascal OSErr HandleODOC(AppleEvent *aMessage,
- AppleEvent *aReply, long aRefCon);
- static pascal OSErr HandlePDOC(AppleEvent *aMessage,
- AppleEvent *aReply, long aRefCon);
- static pascal OSErr HandleQUIT(AppleEvent *aMessage,
- AppleEvent *aReply, long aRefCon);
-
- pascal OSErr InstallRequiredAppleEvents(void) {
- OSErr theError;
-
- theError = AEInstallEventHandler(kCoreEventClass,
- kAEOpenApplication, (AEEventHandlerUPP)&HandleOAPP, 0, false);
- if (theError == noErr) {
- theError = AEInstallEventHandler(kCoreEventClass,
- kAEOpenDocuments, (AEEventHandlerUPP)&HandleODOC, 0, false);
- }
- if (theError == noErr) {
- theError = AEInstallEventHandler(kCoreEventClass,
- kAEPrintDocuments, (AEEventHandlerUPP)&HandlePDOC, 0, false);
- }
- if (theError == noErr) {
- theError = AEInstallEventHandler(kCoreEventClass,
- kAEQuitApplication, (AEEventHandlerUPP)&HandleQUIT, 0,
- false);
- }
- return theError;
- }
-
- pascal OSErr HandleOAPP(AppleEvent *aMessage, AppleEvent *aReply,
- long aRefCon) {
- OSErr theError;
-
- if (GotAllParameters(aMessage)) {
- theError = DoNewCommand();
- } else {
- theError = errAEParamMissed;
- }
- return theError;
- }
-
- Boolean GotAllParameters(AppleEvent *aMessage) {
- Boolean gotAllParameters;
- DescType theType;
- Size theSize;
- OSErr theError;
-
- theError = AEGetAttributePtr(aMessage, keyMissedKeywordAttr,
- typeWildCard, &theType, nil, 0, &theSize);
- if (theError == errAEDescNotFound) {
- gotAllParameters = true;
- } else {
- gotAllParameters = false;
- }
- return gotAllParameters;
- }
-
- pascal OSErr HandleODOC(AppleEvent *aMessage, AppleEvent *aReply,
- long aRefCon) {
- OSErr theError;
- AEDescList theDocuments;
- long item, numItems;
- AEKeyword theKeyword;
- DescType theType;
- FSSpec theFile;
- Size theSize;
-
- theError = AEGetParamDesc(aMessage, keyDirectObject, typeAEList,
- &theDocuments);
- if (theError == noErr) {
- if (GotAllParameters(aMessage)) {
- theError = AECountItems(&theDocuments, &numItems);
- if (theError == noErr) {
- for (item = 1; item <= numItems; item++) {
- theError = AEGetNthPtr(&theDocuments, item, typeFSS,
- &theKeyword, &theType, &theFile, sizeof(FSSpec),
- &theSize);
- if (theError == noErr) {
- DoOpenCommand(&theFile);
- }
- }
- }
- } else {
- (void)AEDisposeDesc(&theDocuments);
- theError = errAEParamMissed;
- }
- }
- return theError;
- }
-
- pascal OSErr HandlePDOC(AppleEvent *aMessage, AppleEvent *aReply,
- long aRefCon) {
- OSErr theError;
- AEDescList theDocuments;
- long item, numItems;
- AEKeyword theKeyword;
- DescType theType;
- FSSpec theFile;
- Size theSize;
-
- theError = AEGetParamDesc(aMessage, keyDirectObject, typeAEList,
- &theDocuments);
- if (theError == noErr) {
- if (GotAllParameters(aMessage)) {
- theError = AECountItems(&theDocuments, &numItems);
- if (theError == noErr) {
- for (item = 1; item <= numItems; item++) {
- theError = AEGetNthPtr(&theDocuments, item, typeFSS,
- &theKeyword, &theType, &theFile, sizeof(FSSpec),
- &theSize);
- if (theError == noErr) {
- #if 0
- DoPrintFile(theFile);
- #endif
- }
- }
- }
- } else {
- (void)AEDisposeDesc(&theDocuments);
- theError = errAEParamMissed;
- }
- }
- return theError;
- }
-
- pascal OSErr HandleQUIT(AppleEvent *aMessage, AppleEvent *aReply,
- long aRefCon) {
- OSErr theError;
-
- if (GotAllParameters(aMessage)) {
- theError = DoQuit();
- } else {
- theError = errAEParamMissed;
- }
- return theError;
- }
-